package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.APCriteriaDao;
import com.hongxun.modules.bss.entity.APCriteriaEntity;
import com.hongxun.modules.bss.service.APCriteriaService;



@Service("aPCriteriaService")
public class APCriteriaServiceImpl implements APCriteriaService {
	@Autowired
	private APCriteriaDao aPCriteriaDao;
	
	@Override
	public APCriteriaEntity queryObject(String guid){
		return aPCriteriaDao.queryObject(guid);
	}
	
	@Override
	public List<APCriteriaEntity> queryList(Map<String, Object> map){
		return aPCriteriaDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return aPCriteriaDao.queryTotal(map);
	}
	
	@Override
	public void save(APCriteriaEntity aPCriteria){
		if(aPCriteria.getGuid()==null||aPCriteria.getGuid().equals("")) {

			aPCriteria.setGuid(UUID.randomUUID().toString());
		}
		aPCriteriaDao.save(aPCriteria);
	}
	
	@Override
	public void update(APCriteriaEntity aPCriteria){
		aPCriteriaDao.update(aPCriteria);
	}
	
	@Override
	public void delete(String guid){
		aPCriteriaDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		aPCriteriaDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<APCriteriaEntity> entities) {
		for (APCriteriaEntity d : entities) {
			if (d.getPCDatastate().equals("删除")) {
				aPCriteriaDao.delete(d.getGuid());
			} else {
				APCriteriaEntity apCriteriaEntity = aPCriteriaDao.queryObject(d.getGuid());
				if (apCriteriaEntity == null) {
					aPCriteriaDao.save(d);
				} else {
					aPCriteriaDao.update(d);
				}
			}
		}
	}
}
